{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import requests \n",
    "from bs4 import  BeautifulSoup\n",
    "import re\n",
    "import time\n",
    "import sqlite3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "url1 = \"http://wsjs.saic.gov.cn/txnS01.do\"\n",
    "url2 = 'http://wsjs.saic.gov.cn/txnS01.do?locale=zh_CN&y7bRbP=KaobksVTJsVTJsVTqAP6E1LUP_6foA13bpNsesgwlOV'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'http://wsjs.saic.gov.cn/txnRead02.ajax?MmEwMD=1Si3yIHkuAdLavTvDZYhKJua9KTrscZQDnzh.3UWfcA7i1Juk4t_Gpg9w2n9BtfHDV2_XeLfOjB0dcKLXYnV1u4mfnjcx6Ljdz1jUGSLLfwZHwHhSpascJ4kdS3m1X17Q71K0P53FVmdz9DknW.EjAIiVufChcCxbFSO8vsF6zKTxGOJqKeqJiigjoMmesShM9IMlqxc77GUEQrPNrps4fo1s1U3y7NjM82084ufFsRd_55lOv0udhAvTxseopns0YJ7SoIehONp21eItG0e7j.1NiBwxU5PnOCLNLeGsI7zQD6lm.kVjJsbMhJ0Bw4HhL4AWek41JyH79uVhx_yNkEGKVTCeHfh.m0hwpqnIgXhrO.TuxB_xH.G6EBOmht4cI.ZWhrdLsMVMEZ'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "url_f = 'http://wsjs.saic.gov.cn/txnRead02.ajax?MmEwMD=1Si3yIHkuAdLavTvDZYhKJua9KTrscZQDnzh.3UWfcA7i1Juk4t_Gpg9w2n9BtfHDV2_XeLfOjB0dcKLXYnV1u4mfnjcx6Ljdz1jUGSLLfwZHwHhSpascJ4kdS3m1X17Q71K0P53FVmdz9DknW.EjAIiVufChcCxbFSO8vsF6zKTxGOJqKeqJiigjoMmesShM9IMlqxc77GUEQrPNrps4fo1s1U3y7NjM82084ufFsRd_55lOv0udhAvTxseopns0YJ7SoIehONp21eItG0e7j.1NiBwxU5PnOCLNLeGsI7zQD6lm.kVjJsbMhJ0Bw4HhL4AWek41JyH79uVhx_yNkEGKVTCeHfh.m0hwpqnIgXhrO.TuxB_xH.G6EBOmht4cI.ZWhrdLsMVMEZ'\n",
    "url_f"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "headers1 = {'Host':'wsjs.saic.gov.cn',\n",
    "           'Upgrade-Insecure-Requests':'1',\n",
    "           'User-Agent':'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36}'\n",
    "          }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'attribute-node': 'record_cache-flag:false',\n",
       " 'attribute-node:record_page': '1',\n",
       " 'attribute-node:record_page-row': '50',\n",
       " 'attribute-node:record_sort-column': 'RELEVANCE',\n",
       " 'attribute-node:record_start-row': '1',\n",
       " 'request:hnc': '',\n",
       " 'request:hne': '',\n",
       " 'request:imf': '',\n",
       " 'request:maxHint': '',\n",
       " 'request:mi': 'D3B954F268FF4B7484BDB4AA99C403CF',\n",
       " 'request:mn': '颐麦坊',\n",
       " 'request:nc': '30',\n",
       " 'request:ncs': '',\n",
       " 'request:queryAuto': '1',\n",
       " 'request:queryCom': '',\n",
       " 'request:queryExp': 'nc = 30 AND ( ((mncc = 颐麦坊) OR (mncc=?颐麦坊 OR mncc=颐?麦坊 OR mncc=颐麦?坊 OR mncc=颐麦坊?) OR (mncc=?麦坊 OR mncc=颐?坊 OR mncc=颐麦? OR mncc=?颐坊 OR mncc=麦?坊) OR (mncc=麦坊 OR mncc=颐坊 OR mncc=颐麦) OR (mncc=颐麦 OR mncc=麦坊 OR mncc=颐坊) OR (mncc=颐坊麦 OR mncc=麦颐坊 OR mncc=麦坊颐 OR mncc=坊颐麦 OR mncc=坊麦颐) OR (mncbc=颐麦坊)) OR mnoc=颐麦坊 )',\n",
       " 'request:queryMode': '1',\n",
       " 'request:queryType': '',\n",
       " 'request:sn': '',\n",
       " 'request:tlong': 'apMT4CyEtcAFTRDtgtzzEQmadzteLV/5UggopczLPqMXYAPFhymvA2oc2X8sUFW5'}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = {'request:queryType':'',\n",
    "    'request:queryAuto':'1',\n",
    "    'request:queryMode':'1',\n",
    "    'request:queryCom':'',\t\n",
    "    'request:mn':'颐麦坊',   \t\n",
    "    'request:ncs':'',\n",
    "    'request:nc':'30',\t\n",
    "    'request:hnc':'',\t\n",
    "    'request:hne':'',\t\n",
    "    'request:sn':'',\t\n",
    "    'request:imf':'',\t\n",
    "    'request:maxHint':'',\t\n",
    "    'request:queryExp':'nc = 30 AND ( ((mncc = 颐麦坊) OR (mncc=?颐麦坊 OR mncc=颐?麦坊 OR mncc=颐麦?坊 OR mncc=颐麦坊?) OR (mncc=?麦坊 OR mncc=颐?坊 OR mncc=颐麦? OR mncc=?颐坊 OR mncc=麦?坊) OR (mncc=麦坊 OR mncc=颐坊 OR mncc=颐麦) OR (mncc=颐麦 OR mncc=麦坊 OR mncc=颐坊) OR (mncc=颐坊麦 OR mncc=麦颐坊 OR mncc=麦坊颐 OR mncc=坊颐麦 OR mncc=坊麦颐) OR (mncbc=颐麦坊)) OR mnoc=颐麦坊 )',\n",
    "    'request:mi':'D3B954F268FF4B7484BDB4AA99C403CF',\t\n",
    "    'request:tlong':'apMT4CyEtcAFTRDtgtzzEQmadzteLV/5UggopczLPqMXYAPFhymvA2oc2X8sUFW5',\t\n",
    "    'attribute-node':'record_cache-flag:false',\n",
    "    'attribute-node:record_start-row':'1',\n",
    "    'attribute-node:record_page-row':'50',\n",
    "    'attribute-node:record_sort-column':'RELEVANCE',\n",
    "    'attribute-node:record_page':'1'\n",
    "    }\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',\n",
       " 'Accept-Encoding': 'gzip, deflate',\n",
       " 'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4',\n",
       " 'Cache-Control': 'no-cache',\n",
       " 'Connection': 'keep-alive',\n",
       " 'Content-Length': '1399',\n",
       " 'Host': 'wsjs.saic.gov.cn',\n",
       " 'Origin': 'http://wsjs.saic.gov.cn',\n",
       " 'Pragma': 'no-cache',\n",
       " 'Referer': 'http://wsjs.saic.gov.cn/txnRead01.do?y7bRbp=qmMn0XlK70B26AjTqgIJDr0M1GGWnjtELJdKl9623wVvHTRwH6YL6dPfcEiB_w0kFSbpVKWOvaiuYo.shqXM.PwabTUfgvUh_4sPHcOzFGm2GSJNPChzt5TL4hxSc7R_h9nHqFdlcycITrqs',\n",
       " 'Upgrade-Insecure-Requests': '1',\n",
       " 'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36'}"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "headers2 = {\n",
    "       'Host': 'wsjs.saic.gov.cn',\n",
    "       'Upgrade-Insecure-Requests': '1',\n",
    "       'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36',\n",
    "       'Pragma': 'no-cache',\n",
    "       'Referer': 'http://wsjs.saic.gov.cn/txnRead01.do?y7bRbp=qmMn0XlK70B26AjTqgIJDr0M1GGWnjtELJdKl9623wVvHTRwH6YL6dPfcEiB_w0kFSbpVKWOvaiuYo.shqXM.PwabTUfgvUh_4sPHcOzFGm2GSJNPChzt5TL4hxSc7R_h9nHqFdlcycITrqs',\n",
    "       'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',\n",
    "       'Accept-Encoding': 'gzip, deflate',\n",
    "       'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4',\n",
    "       'Cache-Control': 'no-cache',\n",
    "       'Connection': 'keep-alive',\n",
    "       'Origin':'http://wsjs.saic.gov.cn',\t\n",
    "       'Content-Length':'1399'\n",
    "       }\n",
    "headers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "with requests.Session() as s:\n",
    "    res1 = s.get(url1, headers=headers1)\n",
    "    time.sleep(1)\n",
    "    res2 = s.post(url_f, headers=headers2)\n",
    "res2.url"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "res1.url"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
